package com.leetcode;

import ds.TreeNode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No112
 * @description
 * @date 2021/3/3 下午1:14
 */
public class No112 {
    public static void main(String[] args) {
        TreeNode t1 = new TreeNode(1);
        TreeNode t2 = new TreeNode(2);
        TreeNode t3 = new TreeNode(3);
        t1.left = t2;
        t1.right = t3;
        boolean res = hasPathSum(t1,5);
        System.out.println(res);

    }

    public static boolean hasPathSum(TreeNode root, int targetSum) {
        if(root == null){
            return false;
        }
        targetSum -= root.val;
        if(root.left == null && root.right == null){
            return targetSum == 0;
        }
        return hasPathSum(root.left,targetSum) || hasPathSum(root.right,targetSum);
    }


}
